import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

const loadComponent = (name) => {
  return async (resolve) => {
    const module = await import(`@/components/${name}/${name}`)
    resolve(module)
  }
}
const index = loadComponent('index')
const home =loadComponent('home')
const message =loadComponent('message')
const order =loadComponent('order')
const self =loadComponent('self')

export default new Router({
  routes: [
    {
      path: '/',
      redirect: '/index'
    },
    {
      path: '/index',
      component: index,
      children: [
        {
          path: '/',
          redirect: 'home'
        },
        {
          path: 'home',
          component: home
        },
        {
          path: 'order',
          component: order
        },
        {
          path: 'message',
          component: message
        },
        {
          path: 'self',
          component: self
        }
      ]
    }
  ]
})
